using System;

namespace Neo.Framework
{
    ///<summary>
    ///</summary>
    [Serializable]
    public class EntityValidationError
    {
        private string _entityName;
        private string _message;
        private string _property;

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityValidationError"/> class.
        /// </summary>
        /// <param name="entity">The entity.</param>
        public EntityValidationError(EntityObject entity): this(entity.GetType().Name, null, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityValidationError"/> class.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        public EntityValidationError(EntityObject entity, string propertyName) : this(entity.GetType().Name, propertyName, null)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityValidationError"/> class.
        /// </summary>
        /// <param name="entity">The entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="errorMessage">The error message.</param>
        public EntityValidationError(EntityObject entity, string propertyName, string errorMessage) : this(entity.GetType().Name, propertyName, errorMessage)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="EntityValidationError"/> class.
        /// </summary>
        /// <param name="entityName">Name of the entity.</param>
        /// <param name="propertyName">Name of the property.</param>
        /// <param name="errorMessage">The error message.</param>
        public EntityValidationError(string entityName, string propertyName, string errorMessage)
        {
            _entityName = entityName;
            _property = propertyName;
            _message = errorMessage;
        }

        /// <summary>
        /// Gets or sets the name of the property.
        /// </summary>
        /// <value>The name of the property.</value>
        public string PropertyName
        {
            get { return _property; }
            set { _property = value; }
        }

        /// <summary>
        /// Gets or sets the error message.
        /// </summary>
        /// <value>The error message.</value>
        public string ErrorMessage
        {
            get { return _message; }
            set { _message = value; }
        }

        /// <summary>
        /// Gets or sets the name of the entity.
        /// </summary>
        /// <value>The name of the entity.</value>
        public string EntityName
        {
            get { return _entityName; }
            set { _entityName = value; }
        }

        /// <summary>
        /// Returns the fully qualified type name of this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="T:System.String"></see> containing a fully qualified type name.
        /// </returns>
        public override string ToString()
        {
            return string.Format("{0}.{1}: {2}", _entityName, _property, _message);
        }
    }
}